package com.java2104.service;

import com.java2104.entity.Dept;
import com.java2104.entity.Document;
import com.java2104.mapper.DeptMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class DeptService {
    @Autowired
    private DeptMapper deptMapper;

    public int delete(Integer id){
       return deptMapper.delete(id);
    }
    public int findKey(Integer id){
        return deptMapper.selectKey(id);
    }
    public Dept get(Integer id){
        return deptMapper.findByPrimaryKey(id);
    }
    public List<Dept> selectDeptName(String name){
        return deptMapper.selectDeptName(name);

    }
    public Map updateremark(Dept dept){
        Map map=new HashMap();
        if (deptMapper.updateremark(dept)>0){
            map.put("remark","success");
            map.put("msg","部门信息修改成功");

        }else {
            map.put("remark","fail");
            map.put("msg","部门信息修改失败");

        }
        return map;
    }
 public Map save(Dept dept){
   Map map=new HashMap();
   if (deptMapper.selectname(dept.getName())==0){
       deptMapper.insert(dept);
       map.put("name","success");
       map.put("msg","添加成功");
   }else {
       map.put("name","fail");
       map.put("msg","添加失败,名字重复");
   }
   return map;
 }
}
